package peerToPeerFacebook.proj;

import java.io.Serializable;
import java.util.Observer;

/** This interface is used in RPC to signal that call has not completed. Basically, callee can return instance
 * of this interface and not the value. RPC will query this interface from time to time until it returns value. At this
 * point RPC will inform client that the call completed.
 * 
 * In case crash happens while the call is pending RPC will return at most once semantics.
 */
public interface CallPending 
{
    /** Indicates if the call is completed. RPC will call this method from time to to time to check if the call has
     * finished.
     * 
     * @return True if the call has finished
     */
    public boolean completed();
    
    /** Returns result of the call. This method is only defined if completed returned true. It is perfectly fine for 
     * this method to throw exception. If this happens this exception will be bundled and sent to client.
     * @return Return value of the call.
     */
    public Serializable result() throws Throwable;
    
    /** Adds observer that will be signaled when result is changed */
    public void addObserver(Observer o);
}
